package com.tiut.lmap.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tiut.lmap.mapper.ChatMapper;
import com.tiut.lmap.model.pojo.Chat;
import com.tiut.lmap.service.ChatService;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author wlf
 * @description 针对表【chat(用户)】的数据库操作Service实现
 * @createDate 2025-04-14 10:13:52
 */
@Service
public class ChatServiceImpl extends ServiceImpl<ChatMapper, Chat>
        implements ChatService {

//    @Override
//    public void save(String type, String chatId) {
//        //判断列表是否存在，不存在则创建
//        if (!chatHistory.containsKey(type)) {
//            chatHistory.put(type, new HashSet<String>());
//        }
//        //插入
//        Set<String> ids = chatHistory.get(type);
//        if (ids.contains(chatId)) {
//            return;
//        }
//        ids.add(chatId);
//    }

    @Override
    public Set<String> getChatIds(String type) {
        QueryWrapper<Chat> chatQueryWrapper = new QueryWrapper<>();
        chatQueryWrapper.select("id").eq("type", type);
        Set<String> ids = this.list(chatQueryWrapper)
                .stream()
                .map(chat -> String.valueOf(chat.getId()))
                .collect(Collectors.toSet());
        if (ids == null) {
            return new HashSet<String>();
        }
        return ids;
    }
}


